package edu.gxmzu.task.controller;

import edu.gxmzu.task.service.MessageService;
import edu.gxmzu.task.utils.JWTUtil;
import edu.gxmzu.task.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "消息模块")
public class MessageController {
    @Resource
    private MessageService messageService;

    @Operation(summary = "删除消息",description = "请求请按如下参数格式：<br/>"+
            "[ '消息id1','消息id2' ]<br/>")
    @PostMapping("/deleteMessage")
    public Result deleteMessage(@RequestHeader(value = "jwtToken") @Schema(description = "请求头携带") String token, @RequestBody List<String> ids){
        String userId= JWTUtil.getUserIdFromToken(token);
        return messageService.deleteMessage(userId,ids);
    }

    @Operation(summary = "消息已读",description = "请求请按如下参数格式：<br/>"+
            "[ '消息id1','消息id2' ]<br/>")
    @PostMapping("/readMessage")
    public Result readMessage(@RequestHeader(value = "jwtToken") @Schema(description = "请求头携带") String token, @RequestBody List<String> ids ){
        String userId= JWTUtil.getUserIdFromToken(token);
        return messageService.readMessage(userId,ids);

    }
}
